package JUC.JMM;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author mubei
 * @date 2021/11/23
 * @description  测试不保证原子性
 */
public class VDemo02 {

    private volatile  static AtomicInteger num = new AtomicInteger();

    public static void add(){
       num.getAndIncrement();
    }
    public static void main(String[] args) {
        for (int i = 0; i < 20; i++) {
            new Thread(()->{
                for (int j = 0; j < 1000; j++) {
                    add();
                }
            }).start();
        }
        while(Thread.activeCount() >2){

        }
        System.out.println(num);
    }
}
